package _3_TwoPointers;

import _2_Linkedlist.ListNode;

public class A18_deleteNode {
    public ListNode deleteNode(ListNode head, int val) {
        //确认第一个点的值不是val
        if (head.val == val)
            return head.next;

        //定义cur和pre指针
        ListNode cur = head.next;
        ListNode pre = head;
        while (cur != null && cur.val != val) {
            pre = cur;
            cur = cur.next;
        }
        if (cur != null) {
            pre.next = cur.next;
        }
        return head;
    }
}
